package com.orm.analysis.controller;

import com.orm.analysis.service.impl.AddressService;
import com.orm.analysis.util.GlobalConst;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/10/13
 * Time: 11:08 AM
 * To change this template use File | Settings | File Templates.
 */
public class AddressCtlr {


    private static Logger logger = Logger.getLogger(AddressCtlr.class);

        public static void main(String[] args) {

    //        configure logging   and start process execution
            try {
                String configFileName = "none";
                configFileName = System.getProperty(GlobalConst.LOG_CONFIGURATION, configFileName);
                org.apache.log4j.PropertyConfigurator.configure(configFileName);
                ApplicationContext springContext = new ClassPathXmlApplicationContext(GlobalConst.PATHS);
                AddressService addressService   = (AddressService) springContext.getBean("addressService");
                addressService.executeImproter();
            } catch (Exception e) {
                logger.error("Application Error", e);
                throw new RuntimeException("Error in process, nothing saved to database",e);
            }

////            System.out.println(55*0.073);
////            System.out.println(Math.round((55*0.073)*100.0)/100.0);
//            System.out.println( 11191.015*100);
//            System.out.println(getRoundVal(4.015*1.0));
//            System.out.println(Math.round(4.035*100.0)/100.0);
//            System.out.println(Math.round(9.055*100.0)/100.0);
//            System.out.println(Math.round(9.045*100.0)/100.0);
//            System.out.println(Math.round(9.035*100.0)/100.0);
//            System.out.println(Math.round(9.025*100.0)/100.0);
//            System.out.println(Math.round(9.015*100.0)/100.0);
//            System.out.println(Math.pow(10, 2));
//            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//
//            DecimalFormat newFormat = new DecimalFormat("#.##");
////            double twoDecimal =  Double.valueOf(newFormat.format(d));
//
//
////            System.out.println( Double.valueOf(newFormat.format(4.015)));
////            System.out.println( Double.valueOf(newFormat.format(4.025)));
////            System.out.println( Double.valueOf(newFormat.format(4.035)));
////            System.out.println( Double.valueOf(newFormat.format(4.045)));
////            System.out.println( Double.valueOf(newFormat.format(4.055)));
////            System.out.println( Double.valueOf(newFormat.format(4.065)));
////            System.out.println(Double.valueOf(String.format("%.3f", 9.0155)));
//            System.out.println(Double.valueOf(String.format("%.2f", 55*0.073)));
//            System.out.println(String.format("%.2f", 4.035));
//            System.out.println(String.format("%.2f", 4.045));
//            System.out.println(String.format("%.2f", 4.055));
//            System.out.println(String.format("%.2f", 4.065));
//            System.out.println(String.format("%.2f", 4.075));
////            System.out.println( (new BigDecimal(4.025).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(4.035).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(4.045).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(4.055).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(4.065).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(4.075).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(9.014).setScale(2, RoundingMode.UP).doubleValue()));
////            System.out.println( (new BigDecimal(9.045).setScale(2, RoundingMode.UP).doubleValue()));




        }

    static double getRoundVal(double d) {

               double p = (double) Math.pow(10, 2);
               double rval = (d) * p;
               double tmp = Math.round(rval);
               rval = tmp / p;
               return rval;
           }

}
